Imports DAL
Imports MyClasses
Imports BAL

Public Class frmSchemeSelection
    Public _intItemID As Integer = 3
    Public _intQnty As Integer
    Public dtInvoicedate As Date
    Public _intSchemeID As Integer
    Public Scheme As Double
    Public Disctype As String
    Public strDC As String = ""  '...Divya@21/01/2008:Declared for getting the scheme

    Dim dtbSchItem As DataTable

    Private Sub frmSchemeSelection_HelpButtonClicked(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles Me.HelpButtonClicked
        'Rauhl_ITS@20073012 : Add following code display help
        'Help.ShowHelp(Me, "Pharma.chm", HelpNavigator.KeywordIndex, "Scheme Selection")
        e.Cancel = True
    End Sub

    Private Sub frmSchemeSelection_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        If e.KeyCode = Keys.Escape Then Me.Close()
    End Sub

    Private Sub frmSchemeSelection_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
        If e.KeyCode = Keys.F1 Then
            'Rauhl_ITS@20073012 : Add following code display help
            e.SuppressKeyPress = True
            'Help.ShowHelp(Me, "Pharma.chm", HelpNavigator.KeywordIndex, "Scheme Selection")
        End If
    End Sub

    Private Sub frmSchemeSelection_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Call BCommon.SetFormStandards(Me)
        Call DisplayData()
    End Sub
    Private Sub DisplayData()
        Try
            cfgScheme.Focus()
            dtbSchItem = BScheme.getSchemeItem(_intItemID, dtInvoicedate)
            With cfgScheme
                .Cols(0).Visible = False
                .Cols(1).Visible = False
                .Cols(2).Visible = True
                .Cols(3).Visible = True
                .Cols(4).Visible = True
                .Cols(5).Visible = True
                .Cols(6).Visible = False
                .Cols(7).Visible = True       '...Divya@28/01/2008
                .Cols(3).TextAlign = C1.Win.C1FlexGrid.TextAlignEnum.RightCenter
                .Cols(4).TextAlign = C1.Win.C1FlexGrid.TextAlignEnum.RightCenter
                .Cols(5).TextAlign = C1.Win.C1FlexGrid.TextAlignEnum.RightCenter
                .Cols(7).TextAlign = C1.Win.C1FlexGrid.TextAlignEnum.GeneralCenter        '...Divya@28/01/2008
            End With
            fillGrid()
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "btnClose_Click")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub fillGrid()
        ' Dim dtbSchItem As DataTable
        Dim intCount As Integer
        Dim intGridCount As Integer
        Try
            cfgScheme.Rows.Count = dtbSchItem.Rows.Count + 4
            If dtbSchItem.Rows.Count > 0 Then
                With cfgScheme
                    intGridCount = 1
                    For intCount = 0 To dtbSchItem.Rows.Count - 1
                        If Trim(strDC) = "DP" And dtbSchItem.Rows(intCount).Item(12) = "F" Then Continue For
                        If Trim(strDC) = "DC" And dtbSchItem.Rows(intCount).Item(1) = 0 Then Continue For
                        .Item(intGridCount, 6) = dtbSchItem.Rows(intCount).Item(10)
                        .Item(intGridCount, 0) = dtbSchItem.Rows(intCount).Item(0)
                        .Item(intGridCount, 1) = dtbSchItem.Rows(intCount).Item(1)
                        .Item(intGridCount, 2) = dtbSchItem.Rows(intCount).Item(2)
                        .Item(intGridCount, 7) = dtbSchItem.Rows(intCount).Item("codeDesc")  '...Divya@28/01/2008
                        If dtbSchItem.Rows(intCount).Item(1) = 0 Then
                            If dtbSchItem.Rows(intCount).Item(10) = "P" Then
                                '.Item(intCount + 1, 3) = dtbSchItem.Rows(intCount).Item(3) & " %"
                                .Item(intGridCount, 3) = dtbSchItem.Rows(intCount).Item(3)
                            Else
                                '.Item(intCount + 1, 3) = Format(dtbSchItem.Rows(intCount).Item(3), "##,##0.00") & " Rs."
                                .Item(intGridCount, 3) = Format(dtbSchItem.Rows(intCount).Item(3), "##,##0.00")
                            End If

                            .Item(intGridCount, 4) = ""
                            .Item(intGridCount, 5) = ""
                        Else
                            .Item(intGridCount, 3) = dtbSchItem.Rows(intCount).Item(3) & "+" & dtbSchItem.Rows(intCount).Item(4)
                            .Item(intGridCount, 4) = dtbSchItem.Rows(intCount).Item(5) & "+" & dtbSchItem.Rows(intCount).Item(6)
                            .Item(intGridCount, 5) = dtbSchItem.Rows(intCount).Item(7) & "+" & dtbSchItem.Rows(intCount).Item(8)
                            ' .Item(intGridCount, 7) = dtbSchItem.Rows(intCount).Item("codeDesc")  '...Divya@28/01/2008
                        End If
                        intGridCount += 1
                    Next
                    'Modified By:-VINIT(2008/01/23)
                    'Set the Current Scheme Row
                    If _intSchemeID > 0 Then
                        Dim SchemRow As Integer = .FindRow(_intSchemeID.ToString(), 1, 0, False, True, True)
                        If SchemRow > 0 Then .Row = SchemRow
                    End If
                End With
            Else
                BCommon.ShowMsgError(10161)
            End If
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "fillGrid")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub ClearData()
        Try
            cfgScheme.Clear(C1.Win.C1FlexGrid.ClearFlags.UserData)
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "ClearData")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        Me.Close()
    End Sub

    Private Sub bnt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bnt.Click
        Try
            Me.Cursor = Cursors.WaitCursor
            Call SaveScheme()
            Me.Cursor = Cursors.Default
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "bnt_Click")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub SaveScheme()
        'Dim intCount As Integer
        Try
            _intSchemeID = cfgScheme.Item(cfgScheme.RowSel, 0)
            Scheme = 0
            'If Not IsNothing(cfgScheme.Item(cfgScheme.Row, 0)) Then
            '    For intCount = 3 To 5
            '        If Not IsNothing(cfgScheme.Item(cfgScheme.Row, intCount)) And cfgScheme.Item(cfgScheme.Row, intCount).ToString <> "0+0" And cfgScheme.Item(cfgScheme.Row, intCount).ToString <> "" Then
            '            If intCount > 3 Then
            '                Scheme = Scheme + "," + CDbl(cfgScheme.Item(cfgScheme.Row, intCount))
            '            Else
            '                Scheme = Scheme + CDbl(cfgScheme.Item(cfgScheme.Row, intCount))
            '            End If
            '        End If
            '    Next
            '    Disctype = cfgScheme.Item(cfgScheme.Row, 6)
            'End If
            Me.Close()
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "SaveScheme")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub btnNew_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNew.Click
        Dim frmSchMaster As New frmSchemeMaster
        Try
            Me.Cursor = Cursors.WaitCursor
            frmSchMaster.itemid = _intItemID
            frmSchMaster.strWindowFlag = "Y"  'Modified By:-Vinit(2008/01/23)
            frmSchMaster.ShowDialog()
            _intSchemeID = frmSchMaster.intSchemeID
            Call ClearData()
            Call DisplayData()
            Me.Cursor = Cursors.Default
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "btnNew_Click")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub btnNew_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNew.MouseLeave
        btnNew.BackColor = Color.AliceBlue
        btnNew.ForeColor = Color.Black
    End Sub

    Private Sub btnNew_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles btnNew.MouseMove
        btnNew.BackColor = Color.LightSeaGreen
        btnNew.ForeColor = Color.White
    End Sub

    Private Sub bnt_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles bnt.MouseLeave
        bnt.BackColor = Color.AliceBlue
        bnt.ForeColor = Color.Black
    End Sub

    Private Sub bnt_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles bnt.MouseMove
        bnt.BackColor = Color.LightSeaGreen
        bnt.ForeColor = Color.White
    End Sub

    Private Sub btnCancel_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnClose.MouseLeave
        btnClose.BackColor = Color.AliceBlue
        btnClose.ForeColor = Color.Black
    End Sub

    Private Sub btnCancel_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles btnClose.MouseMove
        btnClose.BackColor = Color.LightSeaGreen
        btnClose.ForeColor = Color.White
    End Sub

    Private Sub cfgScheme_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles cfgScheme.KeyUp
        Try
            If e.KeyCode = Keys.Enter Then
                bnt.Focus()
            End If
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "cfgScheme_KeyUp")
            Me.Cursor = Cursors.Default
        End Try
    End Sub
End Class